package com.distributedDataBase.config;

import com.distributedDataBase.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class LoginConfig implements WebMvcConfigurer {

    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    /*
    我的因为每次访问都会额外访问一次/favicon.ico导致我多拦截了一次
    我排除掉这个/favicon.ico就正常了，排除的就不会触发拦截，不会走prehandle输出，没排除的就会触发拦截，就会走prehandle判断是否输出一次
    同样的坑还有/error
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/views/**", "/plugins/**", "/imgs/**",
                        "/user/**", "/favicon.ico", "/cookie/**", "/ses/**",
                        "/error/**", "/product/**");
    }
}
